package com.example.administrator.fragmentdemo;

import android.app.Activity;
import android.os.Bundle;
import android.view.Display;

public class MainActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Display dispaly = getWindowManager().getDefaultDisplay();
        //通过切换屏幕可以看到效果
       /* if (dispaly.getHeight() > dispaly.getWidth()) {
            //动态添加Fragment
            //1.获取FragmentManager，在Activity中可以通过getFragmentManager得到
            FragmentManager fragmentManager = getFragmentManager();
            //2.开启一个事务，通过调用beginTransaction方法开启
            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
            //3.向容器中加入Fragment，一般使用replace方法实现，需要传入容器id和Fragment的实例
            fragmentTransaction.replace(R.id.fragment1, new Fragment1());
            //4.提交事务，调用commit方法提交
            fragmentTransaction.commit();
        } else {
            getFragmentManager().beginTransaction().replace(R.id.fragment2, new Fragment2()).commit();
        }*/

        getFragmentManager().beginTransaction().replace(R.id.fragment1, new Fragment1()).commit();
        getFragmentManager().beginTransaction().replace(R.id.fragment2, new Fragment2()).commit();
    }
}
